package online.chazi.bootplus.commons.utils.codec;

/**
 * 说明：作者很懒，什么都没留下
 * Created by 叉子同学 on 2020-05-02 01:38
 */
public class IntUtils {

    public static int fromBytes(byte[] src) {
        int values = 0;
        for (int i = 0; i < 4 && i < src.length; i++) {
            values <<= 8;
            values |= (src[i] & 0xff);
        }
        return values;
    }

    public static byte[] toByteArray(int i) {
        byte[] bt = new byte[4];
        bt[3] = (byte) (0xff & i);
        bt[2] = (byte) ((0xff00 & i) >> 8);
        bt[1] = (byte) ((0xff0000 & i) >> 16);
        bt[0] = (byte) ((0xff000000 & i) >> 24);
        return bt;
    }

    public static void main(String[] args) {
        for (int i = 11111110; i < 11111120; i++) {
            byte[] key = toByteArray(i);
            System.out.println("i=" + i + ", key=" + fromBytes(key));
        }
    }

}
